import type { Camera, Intersection, Object3D, WebGPURenderer } from 'three/webgpu';
import { Signal } from 'yj-tiny-signal';

import type { Editor } from './Editor';

type ObjectRemovedSignalType = {
  object: Object3D;
  parent: Object3D;
};

export const signals = {
  // player

  startPlayer: new Signal(),
  stopPlayer: new Signal(),

  // notifications

  editorCleared: new Signal(),
  savingStarted: new Signal(),
  savingFinished: new Signal(),

  transformModeChanged: new Signal(),
  snapChanged: new Signal(),
  spaceChanged: new Signal(),
  rendererCreated: new Signal<WebGPURenderer>(),
  rendererUpdated: new Signal(),
  rendererDetectKTX2Support: new Signal(),

  sceneBackgroundChanged: new Signal(),
  sceneEnvironmentChanged: new Signal(),
  sceneFogChanged: new Signal(),
  sceneFogSettingsChanged: new Signal(),
  sceneGraphChanged: new Signal(),
  sceneRendered: new Signal(),

  cameraChanged: new Signal(),
  cameraResetted: new Signal<Editor>(),

  geometryChanged: new Signal(),

  objectSelected: new Signal<Object3D | null>(),
  objectFocused: new Signal(),

  objectAdded: new Signal<Object3D>(),
  objectChanged: new Signal<Object3D>(),
  objectRemoved: new Signal<ObjectRemovedSignalType>(),

  cameraAdded: new Signal<Camera>(),
  cameraRemoved: new Signal<Camera>(),

  helperAdded: new Signal<Object3D>(),
  helperRemoved: new Signal<Object3D>(),

  materialAdded: new Signal(),
  materialChanged: new Signal(),
  materialRemoved: new Signal(),

  scriptAdded: new Signal(),
  scriptChanged: new Signal(),
  scriptRemoved: new Signal(),

  windowResize: new Signal(),

  showHelpersChanged: new Signal(),
  refreshSidebarObject3D: new Signal(),
  refreshSidebarEnvironment: new Signal(),
  historyChanged: new Signal(),

  viewportCameraChanged: new Signal(),
  viewportShadingChanged: new Signal(),

  intersectionsDetected: new Signal<Intersection[]>(),
};

export type TypeSignals = typeof signals;
